package com.edu.chat.web.covert;

import com.edu.buservice.util.model.TenantUtil;
import com.edu.chat.facade.model.dto.HistoryMsgDTO;
import com.edu.chat.facade.model.dto.SendMessageDTO;
import com.edu.chat.facade.model.enums.MsgTypeEnum;
import com.edu.chat.web.model.CsMessage;

/**
 * @program: KQAIA
 * @description:
 * @author: 无恙
 * @create: 2025-03-23 18:49
 **/


public class MessageCovert {

	public static HistoryMsgDTO convert(CsMessage csMessage) {
		HistoryMsgDTO historyMsgDTO=new HistoryMsgDTO();
		historyMsgDTO.setContent(csMessage.getContent());
		historyMsgDTO.setId(String.valueOf(csMessage.getId()));
		historyMsgDTO.setType(MsgTypeEnum.getByCode(csMessage.getType()));
		historyMsgDTO.setSessionId(String.valueOf(csMessage.getSessionId()));
		historyMsgDTO.setFromId(String.valueOf(csMessage.getFromId()));
		historyMsgDTO.setTenantId(TenantUtil.getTenantId());
		return historyMsgDTO;
	}

	public static CsMessage convert(SendMessageDTO sendMessageDTO) {
		CsMessage csMessage=new CsMessage();
		csMessage.setSessionId(Long.valueOf(sendMessageDTO.getSessionId()));
		csMessage.setContent(sendMessageDTO.getContent());
		csMessage.setType(sendMessageDTO.getMsgType());
		csMessage.setFromId(Long.valueOf(sendMessageDTO.getUserId()));
		csMessage.setTenantId(sendMessageDTO.getTenantId());
		csMessage.setId(Long.valueOf(sendMessageDTO.getMessageId()));

		return csMessage;
	}
}
